﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using XbdSoft.Contract;
using XbdSoft.Services;
using System.Security.Principal;
using System.Diagnostics;
using Microsoft.Win32;

namespace XbdSoft.ServerHost
{
    class Program
    {
        static void Main(string[] args)
        { 
            try
            {
                var allServiceTypes = new List<Type>() 
            { 
                typeof(AccountService),
                typeof(DownloadService),
                typeof(AutoUpdateService)
            };
                foreach (var serviceType in allServiceTypes)
                {
                    ServiceHost serviceHost = new ServiceHost(serviceType);
                    serviceHost.Open();
                    Console.WriteLine(string.Format("Service {0} start...", serviceType.Name));
                }
                Console.WriteLine("Press Y to exit.");
            }
            catch(Exception ex) 
            {
                Console.WriteLine(ex.Message);
            }

            var ch = Console.Read();
            while (ch != 'Y' && ch!='y')
            {
                ch = Console.Read();
            }
        }

        static void RestartSelfWithEvaluation(string args)
        {
            var psi = new ProcessStartInfo(System.Reflection.Assembly.GetEntryAssembly().Location, args)
            {
                Verb = "runas"
            };
            Process.Start(psi);
        }
        static bool IsAdmin
        {
            get { 
                var pi = new WindowsPrincipal(WindowsIdentity.GetCurrent());
                return pi.IsInRole(WindowsBuiltInRole.Administrator);
            }
        }
    }
}
